/* eslint-disable array-callback-return,no-undef */
import React, { Component } from 'react';
import { Layout, Form, Spin } from 'antd';
import styles from '../../index.less';
import Toolbar from '../Common/ToolBar/ToolBarNew';
import CommonBase from '../Common/CommonBase';
import CommonClassifyEvent from '../Common/CommonClassifyEvent';
import StaticEditTable from '../Common/CommonTable'; /* 可编辑表格 */
import * as commonBusiness from '../Common/commonBusiness'; /* 单据业务功能 */
import * as commonFunc from '../Common/commonFunc'; /* 通用单据方法 */ /* 通用单据方法 */
import * as commonConfig from '../../utils/config';
import SearchComponent from '../Common/SearchComponent'; /* 搜索组件 */
import * as commonUtils from '../../utils/utils';

const { Header, Content } = Layout;

class CommonClassify extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }
  render() {
    const { pageLoading } = this.props;
    return (
      <div>
        <Spin spinning={pageLoading}>
          <div>
            <CommonClassifyComponent
              {...this.props}
              {...this.state}
            />
          </div>
        </Spin>
      </div>
    );
  }
}
const CommonClassifyComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form);
    return obj;
  },
})((props) => {
  const {
    form, onReturnForm, slavePagination,
  } = props;
  /*   回带表单   */
  onReturnForm(form);
  const pagination = {
    ...slavePagination,
    onChange: props.onPaginationChange,
    size: 'large',
    pageSize: commonConfig.pageSize,
    showQuickJumper: true,
  };
  const tableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    tableProps: { pagination },
  };
  return (
    <Form>
      <Layout>
        <Header className={styles.header}>
          <Toolbar
            {...props}
          />
        </Header>
        <Layout className={styles.clayout}>
          {
            commonUtils.isNotEmptyStr(props.sModelsType) ?
              <Content className={styles.content}>
                <SearchComponent {...props} />
              </Content>
              :
              ''
          }
          <Content className={styles.content}>
            <StaticEditTable {...tableProps} />
          </Content>
        </Layout>
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonClassifyEvent(CommonClassify));

